using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.Constants.NPCs;
using WCell.Constants.Items;
using WCell.Constants.GameObjects;
using WCell.Constants.Spells;
using WCell.Constants.Pets;

namespace WCell.Constants
{
	public static class Extensions
	{
		public static string ToString(this ObjectTypeId type, uint id)
		{
			string entryStr;
			if (type == ObjectTypeId.Item)
			{
				entryStr = (ItemId)id + " (" + id + ")";
			}
			else if (type == ObjectTypeId.Unit)
			{
				entryStr = (NPCId)id + " (" + id + ")";
			}
			else if (type == ObjectTypeId.GameObject)
			{
				entryStr = (GOEntryId)id + " (" + id + ")";
			}
			else
			{
				entryStr = id + " (" + id + ")";
			}
			return entryStr;
		}

		public static string ToString(this GOEntryId id)
		{
			return id + "(Id: " + (int)id + ")";
		}

		public static bool And(this NPCFlags flags, NPCFlags flag)
		{
			return (flags & flag) != 0;
		}

		public static bool And(this ZoneFlags mask, ZoneFlags matchMask)
		{
			return (mask & matchMask) != ZoneFlags.None;
		}

		public static bool And(this ProcTriggerFlags mask, ProcTriggerFlags matchMask)
		{
			return (mask & matchMask) != ProcTriggerFlags.None;
		}

		public static bool Has(this AuraStateMask mask, AuraState state)
		{
			return (mask & (AuraStateMask)(1 << ((int)state - 1))) != 0u;
		}

		public static bool Has(this DamageSchoolMask mask, DamageSchool value)
		{
			return (mask & (DamageSchoolMask)(1 << ((int)value - 1))) != 0u;
		}

		public static bool Has(this PetFoodMask mask, PetFood food)
		{
			return (mask & (PetFoodMask)(1 << ((int)food - 1))) != 0u;
		}

        public static bool Has(this MonsterMoveFlags flags, MonsterMoveFlags toCheck)
        {
            return (flags & toCheck) != 0;
        }

        public static bool Has(this NPCFlags flags, NPCFlags flag)
        {
            return (flags & flag) != 0;
        }

		public static bool Has(this PetFlags flags, PetFlags flag)
        {
            return (flags & flag) != 0;
        }
		
        /// <summary>
        /// Whether the given flags has any of the specified flags
        /// </summary>
        /// <param name="flags"></param>
        /// <param name="toCheck"></param>
        /// <returns></returns>
        public static bool HasAny(this HitFlags flags, HitFlags toCheck)
        {
            return (flags & toCheck) != 0;
		}

		public static bool IsPvP(this RealmServerType type)
		{
			return (type & (RealmServerType.PVP | RealmServerType.RPPVP)) != 0;
		}
	}
}
